﻿using System;
using System.Globalization;

namespace CSharp.Common.TimeOperation
{
    public class TimeHelper
    {
        public static string DateDiff(DateTime DateTime1, DateTime DateTime2)
        {
            string str = null;
            try
            {
                TimeSpan span = (TimeSpan)(DateTime2 - DateTime1);
                if (span.Days >= 1)
                {
                    return (DateTime1.Month.ToString() + "months" + DateTime1.Day.ToString() + "days");
                }
                if (span.Hours > 1)
                {
                    return (span.Hours.ToString() + "hours before");
                }
                str = span.Minutes.ToString() + "minutes before";
            }
            catch
            {
            }
            return str;
        }

        public static int GetMonthLastDate(int year, int month)
        {
            DateTime time = new DateTime(year, month, new GregorianCalendar().GetDaysInMonth(year, month));
            return time.Day;
        }

        public static int SecondToMinute(int Second)
        {
            decimal d = Second / 60M;
            return Convert.ToInt32(Math.Ceiling(d));
        }
    }
}

